package com.ymatou.paygetway.testcase;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.http.client.ClientProtocolException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.ymatou.iapi.payment.parameter.AcquireOrderBean;
import com.ymatou.iapi.payment.parameter.FastRefundBean;
import com.ymatou.iapi.payment.parameter.HipoNotifyBean;
import com.ymatou.iapi.payment.parameter.PayOrderEnum;
import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymatou.mq.admin.parameter.MessageListBean;
import com.ymatou.paygetway.parameter.ApplePayNotifyBean;
import com.ymatou.paygetway.parameter.OrderNotifyBean;
import com.ymatou.paygetway.service.OrderNotifyCall;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.business.service.MqQueryCallService;
import com.ymttest.business.service.PayGateWayCallService;
import com.ymttest.database.model.Account;
import com.ymttest.database.model.AccountEntry;
import com.ymttest.database.model.MPayment;
import com.ymttest.database.model.MRefund;
import com.ymttest.database.sqlwapper.AccountWapper;
import com.ymttest.database.sqlwapper.PayGateWayWapper;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;
/**
*分期乐订单通知
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_OrderNotify{
	private static OrderNotifyBean ordernotifyBean;
	private static OrderNotifyCall ordernotifyCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("分期乐订单通知");
	}

	@Before
	public void caseUp() {
		ordernotifyBean=new OrderNotifyBean();
		ordernotifyCall=new OrderNotifyCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(ordernotifyCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	private void verifyDB(AcquireOrderBean aqb, OrderNotifyBean OrderNotifyBean) throws InterruptedException {
		Logger.comment("验证pp_payment");
		MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
		Logger.debug("PPPayment:" + FormatUtil.beanToGSONString(ppm));
		if (ppm.getInstitutionPaymentId() == null) {
			Thread.sleep(5000);
			ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
		}
		if(OrderNotifyBean.getMerch_sale_state()==12||OrderNotifyBean.getMerch_sale_state()==14) {
			Logger.verifyEquals(PayOrderEnum.Success.getValue(), ppm.getPayStatus(), "验证PayStatus");
		}else if(OrderNotifyBean.getMerch_sale_state()==10) {
			Logger.verifyEquals(PayOrderEnum.Init.getValue(), ppm.getPayStatus(), "验证PayStatus");
			Logger.verifyEquals(null, ppm.getInstitutionPaymentId(), "验证InstitutionPaymentId");
			return;
		}else {
			Logger.verifyEquals(PayOrderEnum.Init.getValue(), ppm.getPayStatus(), "验证PayStatus");
			Logger.verifyEquals(null, ppm.getInstitutionPaymentId(), "验证InstitutionPaymentId");
			return;
		}
		// Logger.verifyEquals("156", ppm.getActualPayCurrencyType(),
		// "验证ActualPayCurrencyType");
		Logger.verifyEquals(OrderNotifyBean.getOrder_id(), ppm.getInstitutionPaymentId(), "验证InstitutionPaymentId");

		Logger.comment("验证AccountEntry");
		String pid = ppm.getPaymentId();
		Map m = new HashMap();
		m.put("bizno", pid);
		List<AccountEntry> list = new AccountWapper().selectAccountEntryByBizNo(m);
		Logger.verifyEquals(1, list.size(), "验证资金条数");
		AccountEntry actinfo = list.get(0);
		Logger.debug(FormatUtil.beanToGSONString(actinfo));
		Logger.verifyEquals(aqb.getUserId(), actinfo.getUserId().toString(), "验证Userid");
		Logger.verifyEquals(0, actinfo.getAmount().compareTo(new BigDecimal(aqb.getPayPrice())), "验证PayPrice:" + aqb.getPayPrice());
		// 入账 type 2
		Logger.verifyEquals("2", actinfo.getEntryType().toString(), "验证Entrytype");
		Logger.verifyEquals(pid, actinfo.getBizNo(), "验证Bizno为PaymentId");
		Logger.verifyEquals(aqb.getOrderId(), actinfo.getOriginalNo(), "验证Originalno为orderid");
		Account nactinfo = new AccountWapper().selectAccountInfo(actinfo.getAccountId()).get(0);
		if (aqb.getBizCode().equals("1")) {
			Logger.verifyEquals("100002", actinfo.getBizCode().toString(), "验证Bizcode");
			Logger.verifyEquals("补款充值", actinfo.getMemo(), "验证Memo");
			Logger.comment("验证AccountInfo:卖家保证金充值");
			Logger.verifyEquals("1", nactinfo.getAccountType().toString(), "验证iAccountType");
			Logger.verifyEquals("1", nactinfo.getCurrencyType().toString(), "验证iCurrencyType");
		} else if (aqb.getBizCode().equals("2")) {
			Logger.verifyEquals("100003", actinfo.getBizCode().toString(), "验证Bizcode");
			Logger.verifyEquals("现金充值", actinfo.getMemo(), "验证Memo");
			Logger.comment("验证AccountInfo:卖家保证金充值");
			Logger.verifyEquals("1", nactinfo.getAccountType().toString(), "验证iAccountType");
			Logger.verifyEquals("1", nactinfo.getCurrencyType().toString(), "验证iCurrencyType");
		} else if (aqb.getBizCode().equals("3")) {
			Logger.verifyEquals("100001", actinfo.getBizCode().toString(), "验证Bizcode");
			Logger.verifyEquals("定金充值", actinfo.getMemo(), "验证Memo");
			Logger.comment("验证AccountInfo:卖家保证金充值");
			Logger.verifyEquals("1", nactinfo.getAccountType().toString(), "验证iAccountType");
			Logger.verifyEquals("1", nactinfo.getCurrencyType().toString(), "验证iCurrencyType");
		} else if (aqb.getBizCode().equals("4")) {
			Logger.verifyEquals("100003", actinfo.getBizCode().toString(), "验证Bizcode");
			Logger.verifyEquals("卖家保证金充值", actinfo.getMemo(), "验证Memo");
			Logger.comment("验证AccountInfo:卖家保证金充值");
			Logger.verifyEquals("11", nactinfo.getAccountType().toString(), "验证iAccountType");
			Logger.verifyEquals("1001", nactinfo.getCurrencyType().toString(), "验证iCurrencyType");
		}else if (aqb.getBizCode().equals("6")) {
			Logger.verifyEquals("100007", actinfo.getBizCode().toString(), "验证Bizcode");
			Logger.verifyEquals("预售定金充值", actinfo.getMemo(), "验证Memo");
			Logger.comment("验证AccountInfo:预售定金充值");
			Logger.verifyEquals("1", nactinfo.getAccountType().toString(), "验证iAccountType");
			Logger.verifyEquals("1", nactinfo.getCurrencyType().toString(), "验证iCurrencyType");
		}
	}
	private void verifyMq(String userId) throws ClientProtocolException, IOException, InterruptedException {
		MessageListBean MessageListBean = MqQueryCallService.initFqlSyncMemberinfo(userId);
		List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
		if(joa.size()==0){
			Thread.sleep(5000);
			 joa = MqQueryCallService.GetMqMessage(MessageListBean);
		}
		Logger.verifyEquals(true, joa.size()>0, "验证发送总线消息");
		Logger.comment(FormatUtil.beanToGSONString(joa));
		
	}
		
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_OrderNotify_001() {
		Logger.start(true,"分期乐订单通知成功-支付成功merch_sale_state12");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			Integer uid  = urrc.getUserid();
			PayGateWayCallService.RegFqlMember(uid); 
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("90");
			aqb.setUserId(uid.toString());
			PayGateWayCallService.acquireOrder(aqb);
			Thread.sleep(1000);
			ordernotifyBean=PayGateWayCallService.initFQLOrderNotifyBean(aqb);
			Map m = new HashMap<String, String>();
			m.put("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			m.put("MockId", mockid);
			String openid=TestDataManager.getRandomUUID().toString().replaceAll("-", "");
			PayGateWayCallService.addMock(ordernotifyCall, m);
			ordernotifyCall.setData(ordernotifyBean);
			ordernotifyCall.callService();			
			Logger.verifyEquals("0", ordernotifyCall.getString("result"), "验证result");
			verifyDB(aqb, ordernotifyBean);
			MessageListBean MessageListBean = MqQueryCallService.initFqlSyncMemberinfo(uid.toString());
			List<Map> mqmsg = MqQueryCallService.GetMqMessage(MessageListBean);
			Logger.verifyEquals(true, mqmsg.size() == 1, "验证总线消息");
			if(mqmsg.size()>0) {
				Logger.debug(FormatUtil.beanToGSONString(mqmsg));
				Logger.verifyEquals(uid.toString(), mqmsg.get(0).get("userId").toString(), "验证uid");
//				Logger.verifyEquals(ppm.getInstProxyPaymentId(), mqmsg.get(0).get("prePayId"), "验证prePayId");
//				Logger.verifyEquals(ppm.getTradingId(), mqmsg.get(0).get("tradingId"), "验证tradingId");
//				Logger.verifyEquals(ppm.getUserId(), mqmsg.get(0).get("userId"), "验证userId");
//				Logger.verifyEquals(YMTDateUtil.getFormatTime(ppm.getPayTime(), "yyyy-MM-dd HH:mm:ss"), mqmsg.get(0).get("payTime"), "验证PayTime");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_OrderNotify_002() {
		Logger.start(true,"分期乐订单通知成功-支付成功merch_sale_state14");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			Integer uid  = urrc.getUserid();
			PayGateWayCallService.RegFqlMember(uid); 
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("90");
			aqb.setUserId(uid.toString());
			PayGateWayCallService.acquireOrder(aqb);
			Thread.sleep(1000);
			ordernotifyBean=PayGateWayCallService.initFQLOrderNotifyBean(aqb);
			ordernotifyBean.setMerch_sale_state(14);
			Map m = new HashMap<String, String>();
			m.put("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			m.put("MockId", mockid);
			String openid=TestDataManager.getRandomUUID().toString().replaceAll("-", "");
			PayGateWayCallService.addMock(ordernotifyCall, m);
			ordernotifyCall.setData(ordernotifyBean);
			ordernotifyCall.callService();			
			Logger.verifyEquals("0", ordernotifyCall.getString("result"), "验证result");
			verifyDB(aqb, ordernotifyBean);
			verifyMq(aqb.getUserId());
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	

	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_OrderNotify_003() {
		Logger.start(true,"分期乐订单通知成功-支付成功merch_sale_state15");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			Integer uid  = urrc.getUserid();
			PayGateWayCallService.RegFqlMember(uid); 
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("90");
			aqb.setUserId(uid.toString());
			PayGateWayCallService.acquireOrder(aqb);
			ordernotifyBean=PayGateWayCallService.initFQLOrderNotifyBean(aqb);
			ordernotifyBean.setMerch_sale_state(15);
			Map m = new HashMap<String, String>();
			m.put("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			m.put("MockId", mockid);
			String openid=TestDataManager.getRandomUUID().toString().replaceAll("-", "");
			PayGateWayCallService.addMock(ordernotifyCall, m);
			ordernotifyCall.setData(ordernotifyBean);
			ordernotifyCall.callService();			
			Logger.verifyEquals("0", ordernotifyCall.getString("result"), "验证result");
			verifyDB(aqb, ordernotifyBean);
			verifyMq(aqb.getUserId());
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_OrderNotify_004() {
		Logger.start(true,"分期乐订单通知成功-支付成功merch_sale_state17");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			Integer uid  = urrc.getUserid();
			PayGateWayCallService.RegFqlMember(uid); 
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("90");
			aqb.setUserId(uid.toString());
			PayGateWayCallService.acquireOrder(aqb);
			ordernotifyBean=PayGateWayCallService.initFQLOrderNotifyBean(aqb);
			ordernotifyBean.setMerch_sale_state(17);
			Map m = new HashMap<String, String>();
			m.put("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			m.put("MockId", mockid);
			String openid=TestDataManager.getRandomUUID().toString().replaceAll("-", "");
			PayGateWayCallService.addMock(ordernotifyCall, m);
			ordernotifyCall.setData(ordernotifyBean);
			ordernotifyCall.callService();			
			Logger.verifyEquals("0", ordernotifyCall.getString("result"), "验证result");
			verifyDB(aqb, ordernotifyBean);
			verifyMq(aqb.getUserId());
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_OrderNotify_005() {
		Logger.start(true,"分期乐订单通知成功-支付成功merch_sale_state18");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			Integer uid  = urrc.getUserid();
			PayGateWayCallService.RegFqlMember(uid); 
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("90");
			aqb.setUserId(uid.toString());
			PayGateWayCallService.acquireOrder(aqb);
			ordernotifyBean=PayGateWayCallService.initFQLOrderNotifyBean(aqb);
			ordernotifyBean.setMerch_sale_state(18);
			Map m = new HashMap<String, String>();
			m.put("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			m.put("MockId", mockid);
			String openid=TestDataManager.getRandomUUID().toString().replaceAll("-", "");
			PayGateWayCallService.addMock(ordernotifyCall, m);
			ordernotifyCall.setData(ordernotifyBean);
			ordernotifyCall.callService();			
			Logger.verifyEquals("0", ordernotifyCall.getString("result"), "验证result");
			verifyDB(aqb, ordernotifyBean);
			verifyMq(aqb.getUserId());
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_OrderNotify_006() {
		Logger.start(true,"分期乐订单通知成功-待支付merch_sale_state10");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			Integer uid  = urrc.getUserid();
			PayGateWayCallService.RegFqlMember(uid); 
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("90");
			aqb.setUserId(uid.toString());
			PayGateWayCallService.acquireOrder(aqb);
			ordernotifyBean=PayGateWayCallService.initFQLOrderNotifyBean(aqb);
			ordernotifyBean.setMerch_sale_state(10);
			Map m = new HashMap<String, String>();
			m.put("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			m.put("MockId", mockid);
			String openid=TestDataManager.getRandomUUID().toString().replaceAll("-", "");
			PayGateWayCallService.addMock(ordernotifyCall, m);
			ordernotifyCall.setData(ordernotifyBean);
			ordernotifyCall.callService();			
			Logger.verifyEquals("0", ordernotifyCall.getString("result"), "验证result");
			verifyDB(aqb, ordernotifyBean);	
			verifyMq(aqb.getUserId());
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_OrderNotify_007() {
		Logger.start(true,"收到订单号不在系统中的订单通知-无影响");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			Integer uid  = urrc.getUserid();
			PayGateWayCallService.RegFqlMember(uid); 
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("90");
			aqb.setUserId(uid.toString());
			ordernotifyBean=PayGateWayCallService.initFQLOrderNotifyBean(aqb);
			ordernotifyBean.setMerch_sale_state(10);
			Map m = new HashMap<String, String>();
			m.put("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			m.put("MockId", mockid);
			String openid=TestDataManager.getRandomUUID().toString().replaceAll("-", "");
			PayGateWayCallService.addMock(ordernotifyCall, m);
			ordernotifyCall.setData(ordernotifyBean);
			ordernotifyCall.callService();			
			Logger.verifyEquals("0", ordernotifyCall.getString("result"), "验证result");
			List<MPayment> list = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId());
			Logger.verifyEquals(0, list.size(), "验证无此订单");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_OrderNotify_008() {
		Logger.start(true,"订单金额不正确失败");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			Integer uid  = urrc.getUserid();
			PayGateWayCallService.RegFqlMember(uid); 
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("90");
			aqb.setUserId(uid.toString());
			PayGateWayCallService.acquireOrder(aqb);
			ordernotifyBean=PayGateWayCallService.initFQLOrderNotifyBean(aqb);
			ordernotifyBean.setAmount(1+ordernotifyBean.getAmount());
			Map m = new HashMap<String, String>();
			m.put("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			m.put("MockId", mockid);
			String openid=TestDataManager.getRandomUUID().toString().replaceAll("-", "");
			PayGateWayCallService.addMock(ordernotifyCall, m);
			ordernotifyCall.setData(ordernotifyBean);
			ordernotifyCall.callService();			
			Logger.verifyEquals("-1", ordernotifyCall.getString("result"), "验证result");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_OrderNotify_009() {
		Logger.start(true,"签名不正确失败");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			Integer uid  = urrc.getUserid();
			PayGateWayCallService.RegFqlMember(uid); 
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("90");
			aqb.setUserId(uid.toString());
			PayGateWayCallService.acquireOrder(aqb);
			ordernotifyBean=PayGateWayCallService.initFQLOrderNotifyBean(aqb);
			ordernotifyBean.setAmount(1+ordernotifyBean.getAmount());
//			Map m = new HashMap<String, String>();
//			m.put("Mock", "1");
//			String mockid = TestDataManager.getRandomUUID().toString();
//			m.put("MockId", mockid);
//			String openid=TestDataManager.getRandomUUID().toString().replaceAll("-", "");
//			PayGateWayCallService.addMock(ordernotifyCall, m);
			ordernotifyCall.setData(ordernotifyBean);
			ordernotifyCall.callService();			
			Logger.verifyEquals("-1", ordernotifyCall.getString("result"), "验证result");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_OrderNotify_010() {
		Logger.start(true,"分期乐订单通知成功-支付成功merch_sale_state15退款成功-不会对退款单产生影响");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			Integer uid  = urrc.getUserid();
			PayGateWayCallService.RegFqlMember(uid); 
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("90");
			aqb.setUserId(uid.toString());
			PayGateWayCallService.acquireOrder(aqb);
			PayGateWayCallService.notifyCall(aqb);
			Map rm = new HashMap();
	        rm.put("Mock", "1");
	        String fastrfmockid = TestDataManager.getRandomUUID().toString();
			rm.put("MockId", fastrfmockid);
			rm.put("MockResult-FqlPay-result", "0");
			FastRefundBean fastrefundBean = PayGateWayCallService.fastRefund(aqb,rm);
			
			PayGateWayWapper pdw=new PayGateWayWapper();
			MPayment ppm  = pdw.selectPaymentByTradingid(aqb.getOrderId()).get(0);
			MRefund mrr = pdw.selectRefundRequestByPaymentId(ppm.getPaymentId()).get(0);
			Logger.debug(FormatUtil.beanToGSONString(mrr));
			Logger.verifyEquals(1, mrr.getRefundStatus(), "验证状态");
			ordernotifyBean=PayGateWayCallService.initFQLOrderNotifyBean(aqb);
			ordernotifyBean.setMerch_sale_state(15);
			Map m = new HashMap<String, String>();
			m.put("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			m.put("MockId", mockid);
			String openid=TestDataManager.getRandomUUID().toString().replaceAll("-", "");
			PayGateWayCallService.addMock(ordernotifyCall, m);
			ordernotifyCall.setData(ordernotifyBean);
			ordernotifyCall.callService();			
			Logger.verifyEquals("0", ordernotifyCall.getString("result"), "验证result");
			ppm  = pdw.selectPaymentByTradingid(aqb.getOrderId()).get(0);
			mrr = pdw.selectRefundRequestByPaymentId(ppm.getPaymentId()).get(0);
			Logger.debug(FormatUtil.beanToGSONString(mrr));
			Logger.verifyEquals(1, mrr.getRefundStatus(), "验证状态");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_OrderNotify_011() {
		Logger.start(true,"分期乐订单通知成功-支付成功merch_sale_state12-用户未调用码头注册分期乐");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			Integer uid  = urrc.getUserid();
//			PayGateWayCallService.RegFqlMember(uid); 
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("90");
			aqb.setUserId(uid.toString());
			PayGateWayCallService.acquireOrder(aqb);
			ordernotifyBean=PayGateWayCallService.initFQLOrderNotifyBean(aqb);
			Map m = new HashMap<String, String>();
			m.put("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			m.put("MockId", mockid);
			String openid=TestDataManager.getRandomUUID().toString().replaceAll("-", "");
			PayGateWayCallService.addMock(ordernotifyCall, m);
			ordernotifyCall.setData(ordernotifyBean);
			ordernotifyCall.callService();			
			Logger.verifyEquals("0", ordernotifyCall.getString("result"), "验证result");
			verifyDB(aqb, ordernotifyBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_OrderNotify_012() {
		Logger.start(true,"分期乐订单通知成功-支付成功merch_sale_state12-重复调用");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			Integer uid  = urrc.getUserid();
//			PayGateWayCallService.RegFqlMember(uid); 
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("90");
			aqb.setUserId(uid.toString());
			PayGateWayCallService.acquireOrder(aqb);
			ordernotifyBean=PayGateWayCallService.initFQLOrderNotifyBean(aqb);
			Map m = new HashMap<String, String>();
			m.put("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			m.put("MockId", mockid);
			String openid=TestDataManager.getRandomUUID().toString().replaceAll("-", "");
			PayGateWayCallService.addMock(ordernotifyCall, m);
			ordernotifyCall.setData(ordernotifyBean);
			ordernotifyCall.callService();			
			Logger.verifyEquals("0", ordernotifyCall.getString("result"), "验证result");
			verifyDB(aqb, ordernotifyBean);
			ordernotifyCall.callService();			
			Logger.verifyEquals("0", ordernotifyCall.getString("result"), "验证result");
			verifyDB(aqb, ordernotifyBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	
	public void Tc_OrderNotify_013() {
		Logger.start(true,"分期乐订单通知成功-支付成功-多次不同状态回调");
		try {
			//14-12
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			Integer uid  = urrc.getUserid();
//			PayGateWayCallService.RegFqlMember(uid); 
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("90");
			aqb.setUserId(uid.toString());
			PayGateWayCallService.acquireOrder(aqb);
			ordernotifyBean=PayGateWayCallService.initFQLOrderNotifyBean(aqb);
			ordernotifyBean.setMerch_sale_state(14);
			Map m = new HashMap<String, String>();
			m.put("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			m.put("MockId", mockid);
			String openid=TestDataManager.getRandomUUID().toString().replaceAll("-", "");
			PayGateWayCallService.addMock(ordernotifyCall, m);
			ordernotifyCall.setData(ordernotifyBean);
			ordernotifyCall.callService();			
			Logger.verifyEquals("0", ordernotifyCall.getString("result"), "验证result");
			verifyDB(aqb, ordernotifyBean);
			ordernotifyBean.setMerch_sale_state(12);
//			ordernotifyBean.setOrder_id(TestDataManager.getRandomUUID().toString().replaceAll("-", ""));
			ordernotifyCall.callService();			
			Logger.verifyEquals("0", ordernotifyCall.getString("result"), "验证result");
			verifyDB(aqb, ordernotifyBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_OrderNotify_014() {
		Logger.start(true,"分期乐订单通知成功-支付成功merch_sale_state12-如果不是补单成功统一把CheckStatus设置为0");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			Integer uid  = urrc.getUserid();
			PayGateWayCallService.RegFqlMember(uid); 
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("90");
			aqb.setUserId(uid.toString());
			PayGateWayCallService.acquireOrder(aqb);
			PayGateWayWapper PayGateWayWapper=new PayGateWayWapper();
			MPayment ppm = PayGateWayWapper.selectPaymentByTradingid(aqb.getOrderId()).get(0);
			PayGateWayWapper.updateCheckStatus(ppm.getPaymentId(), "-1");
			Thread.sleep(1000);
			ordernotifyBean=PayGateWayCallService.initFQLOrderNotifyBean(aqb);
			Map m = new HashMap<String, String>();
			m.put("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			m.put("MockId", mockid);
			String openid=TestDataManager.getRandomUUID().toString().replaceAll("-", "");
			PayGateWayCallService.addMock(ordernotifyCall, m);
			ordernotifyCall.setData(ordernotifyBean);
			ordernotifyCall.callService();			
			Logger.verifyEquals("0", ordernotifyCall.getString("result"), "验证result");
			verifyDB(aqb, ordernotifyBean);
			ppm = PayGateWayWapper.selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(0, ppm.getCheckStatus(), "验证checkstatus归零");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_OrderNotify_015() {
		Logger.start(true,"91分期乐订单通知成功-支付成功merch_sale_state12");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			Integer uid  = urrc.getUserid();
			PayGateWayCallService.RegFqlMember(uid); 
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("91");
			aqb.setUserId(uid.toString());
			PayGateWayCallService.acquireOrder(aqb);
			Thread.sleep(1000);
			ordernotifyBean=PayGateWayCallService.initFQLOrderNotifyBean(aqb);
			Map m = new HashMap<String, String>();
			m.put("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			m.put("MockId", mockid);
			String openid=TestDataManager.getRandomUUID().toString().replaceAll("-", "");
			PayGateWayCallService.addMock(ordernotifyCall, m);
			ordernotifyCall.setData(ordernotifyBean);
			ordernotifyCall.callService();			
			Logger.verifyEquals("0", ordernotifyCall.getString("result"), "验证result");
			verifyDB(aqb, ordernotifyBean);
			MessageListBean MessageListBean = MqQueryCallService.initFqlSyncMemberinfo(uid.toString());
			List<Map> mqmsg = MqQueryCallService.GetMqMessage(MessageListBean);
			Logger.verifyEquals(true, mqmsg.size() == 1, "验证总线消息");
			if(mqmsg.size()>0) {
				Logger.debug(FormatUtil.beanToGSONString(mqmsg));
				Logger.verifyEquals(uid.toString(), mqmsg.get(0).get("userId").toString(), "验证uid");
//				Logger.verifyEquals(ppm.getInstProxyPaymentId(), mqmsg.get(0).get("prePayId"), "验证prePayId");
//				Logger.verifyEquals(ppm.getTradingId(), mqmsg.get(0).get("tradingId"), "验证tradingId");
//				Logger.verifyEquals(ppm.getUserId(), mqmsg.get(0).get("userId"), "验证userId");
//				Logger.verifyEquals(YMTDateUtil.getFormatTime(ppm.getPayTime(), "yyyy-MM-dd HH:mm:ss"), mqmsg.get(0).get("payTime"), "验证PayTime");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}